
function refase(){
    tableIn.reload("User");
}

var tableIn = null;


var index;
var tableData;

layui.use(['table','form'], function(){
    var table = layui.table;
    var form = layui.form;
    //第一个实例
    tableIn = table.render({
        elem: '#demo'
        ,url: '/Primary/getUser?isd='+1 //数据接口
        ,id: 'User'
        ,page: true //开启分页
        ,page:{
            layout:['count','prev','page','next','limit'],//展示的按钮
            groups:5,//展示的联想的页码数
            limit:10,//每页的条数
            limits:[10,20],//可选的每页条数
        },cols: [[ //表头
            {field: 'userId', title: 'ID', width:80,align:'center'}
            ,{field: 'userNumber', title: '用户编号',width:100,align:'center'}
            ,{field: 'avatarUrl', title: '用户头像',hide:'true',width:100,templet:function (data){
                    return '<img src="'+data.avatarUrl+'" style="height: 55px;width: 50px;">';
                }}
            ,{field: 'userAccount', title: '用户账号',width: 100,align:'center'}
            ,{field: 'userNickname', title: '用户昵称',width: 100,align:'center'}
            ,{field: 'userSex', title: '性别',width: 100,align:'center'
                ,templet:function (data){
                    if (data.userSex == 0){
                        return '男';
                    }else if (data.userSex == 1){
                        return '女';
                    }
                }}
            ,{field: 'styleDate', title: '学习时长',width: 100,align:'center'}
            ,{field: 'userAmount', title: '用户消费总金额',width: 130,align:'center'}
            ,{field: 'createDate', title: '用户创建时长',align:'center'}
            ,{field: 'isd', title: '用户分辨',align:'center',width: 100,templet:function (d){
                    if (d.isd == 0){
                        return "进思用户";
                    }else if (d.isd == 1){
                        return "非进思用户";
                    }
                }}
            ,{field: 'cz', title: '操作', toolbar: '#barDemo',align:'center'}
        ]], parseData:function (res){
            return{
                "code":res.state,//解析接口状态
                "msg":res.message,//解析提交文本
                "count":res.total,//解析数据长度
                "data":res.data//解析数据列表
            };
        },done:function(){
            tableData = table.cache.User;
        }
        ,toolbar: '#toolDemo'
    });


    // 监听工具条
    table.on('tool(test)', function (obj) {//注：tool是工具条时间名，test是table
        console.log(obj.data.userId);
        console.log(obj.data);
        var e = obj.event;

        if (e === 'see') {
            // layer.msg("查看"+data.id+data.username);
            layer.open({
                type: 2,
                title: '查看',
                content: 'See.html',
                area: ['50%', '90%'],
                success: function (layero, index) {//弹出层成功弹出后的回调函数
                    console.log(obj.data.avatarUrl);

                    // 父页面向子页面传参 -- iframe 层传数据
                    var body = layer.getChildFrame('body', index);//获取iframe页面
                    body.find('#avatarUrl').attr('src',obj.data.avatarUrl);
                    body.find('#userAccount').val(obj.data.userAccount);
                    body.find('#userNickname').val(obj.data.userNickname);
                    body.find('#stu_id').val(obj.data.stu_id);
                    body.find('#styleDate').val(obj.data.styleDate);
                    body.find('#freestyle').val(obj.data.freestyle);
                    body.find('#idCard').val(obj.data.idCard);
                    body.find('#userSex').val(obj.data.userSex);
                    body.find('#userEmail').val(obj.data.userEmail);
                    body.find('#userAmount').val(obj.data.userAmount);
                    body.find('#createDate').val(obj.data.createDate);
                    body.find('#watchNum').val(obj.data.watchNum);
                    body.find('#collectionNum').val(obj.data.collectionNum);
                    body.find('#thumbNum').val(obj.data.thumbNum);

                    localStorage.setItem("url",obj.data.avatarUrl);

                }
            })
        }

    });

    form.on('submit(go)',function (d){
        d = d.field;
        console.log(d);
        table.reload('User',{
            where:{
                userAccount:d.userAccount,
                userNickname: d.userNickname,
                createDate: d.createDate
            },page:{
                page: 1,
                limit:10
            }
        })
    });
    $('#heui').click(function (){
        layer.open({
            type:2,
            title:'高级检索',
            content:'Seniorn.html',
            area:['60%','60%']
        })
    })
});
function cha(userAccount,userNickname,createDate){
    layui.use('table', function () {
        var table=layui.table;

        // console.log(userAccount,idCard,phone,userEmail);
        table.reload('User',{
            where:{
                userAccount:userAccount,
                userNickname: userNickname,
                createDate: createDate
            },page:{
                page: 1,
                limit:10
            }
        })
    })

}